#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;
const int M1 = 1e9 + 7;
const int M2 = 1e9 + 9;

int n, m;
int a[N];
ll fastpow(ll b, ll p, ll mod) {
  ll res = 1;
  while (p) {
    if (p & 1) res = res * b % mod;
    b = b * b % mod;
    p >>= 1;
  }
  return res;
}
ll inv(ll x, ll mod) { return fastpow(x, mod - 2, mod); }
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  if (n == 1)
    cout << m + 1;
  else {
    ll x = (fastpow(n, m + 1, M1) + M1 - 1) % M1 * inv(n - 1, M1) % M1;
    ll y = (fastpow(n, m + 1, M2) + M2 - 1) % M2 * inv(n - 1, M2) % M2;
    if (x == y && x <= 1e9)
      cout << x;
    else
      cout << "inf";
  }
  return 0;
}